----- read product_env,get environment properties
local fd, err = io.open("/usr/local/openresty/nginx/conf/product_env.txt", "rb")
PRODUCT_ENV = fd:read "*a"
PRODUCT_ENV = string.match(PRODUCT_ENV, "(%w+)")
fd:close()

UC_ENV = "online"
local uc_fd, err = io.open("/usr/local/openresty/nginx/conf/uc_env.txt", "rb")
if uc_fd then
    UC_ENV = uc_fd:read "*a"
    UC_ENV = string.match(UC_ENV, "(%w+)")
    uc_fd:close()
end

CLICKHOUSE_LOG_SERVER = {}
if PRODUCT_ENV == "sandbox" then
    CLICKHOUSE_LOG_SERVER.ADDR = "10.2.8.203"
    CLICKHOUSE_LOG_SERVER.PORT = 10045
    UC_ENV = "sandbox"
elseif PRODUCT_ENV == "online" then
    CLICKHOUSE_LOG_SERVER.ADDR = "10.2.8.203"
    CLICKHOUSE_LOG_SERVER.PORT = 10045

    if UC_ENV ~= "pre" then
        UC_ENV = "online"
    end
end

--------------common-----------------------
cjson = require "cjson"
cjson_safe = require "cjson.safe"
luuid = require "luuid"
bit = require "bit"
unicode = require "unicode"

lgzip = require "lgzip"
--aes = require "luaaes"
--aes.init()

--des = require "luades"
-- liping_chang 专用
--aes_v2 = require "luaaes_v2"
--aes_v2.init()

multiupload = require "libs/multipart_upload"
magick = require "magick.init"

nlog = require "libs/nlog"
luaaes_v1 =require "luaaes_v1"
luarsa =require "luarsa"
ase_util = require "libs/ase_util"
rsa_util = require "libs/rsa_util"
ase_config = require "libs/ase_config"
rsa_config = require "config/rsa_config"
md5  = require "libs/md5"

logging = require "libs/logging"
logging_socket = require("socket")
logging_sock = logging_socket.udp()
logging_sock:setoption("reuseaddr",true)
logging_sock:setsockname("0.0.0.0",5012)
logging_sock:setpeername("10.2.21.86",30017)

socket = require("socket")
sock = socket.udp()
sock:setoption("reuseaddr",true)
sock:setsockname("0.0.0.0",5003)
sock:setpeername("10.2.21.167",5351)

dsocket = require("socket")
dsock = dsocket.udp()
dsock:setoption("reuseaddr",true)
dsock:setsockname("0.0.0.0",5004)
dsock:setpeername("10.2.21.167",5351)

hsocket = require("socket")
hsock = hsocket.udp()
hsock:setoption("reuseaddr",true)
hsock:setsockname("0.0.0.0",5005)
hsock:setpeername("10.2.21.167",5351)

gsocket = require("socket")
gsock = gsocket.udp()
gsock:setoption("reuseaddr",true)
gsock:setsockname("0.0.0.0",5007)
gsock:setpeername("10.2.21.167",5351)

ksocket = require("socket")
ksock = ksocket.udp()
ksock:setoption("reuseaddr",true)
ksock:setsockname("0.0.0.0",5007)
ksock:setpeername("10.2.21.167",5351)

httpReqStatSock = socket.udp()
httpReqStatSock:setoption("reuseaddr",true)
httpReqStatSock:setsockname("0.0.0.0", 5008)
httpReqStatSock:setpeername("10.2.21.167", 5351)

lsocket = require("socket")
lsock = hsocket.udp()
lsock:setoption("reuseaddr",true)
lsock:setsockname("0.0.0.0",5006)
lsock:setpeername("10.2.21.167",5351)

ssocket = require("socket")
ssock = ssocket.udp()
ssock:setoption("reuseaddr",true)
ssock:setsockname("0.0.0.0",5007)
ssock:setpeername("10.2.21.167",5351)

qsocket = require("socket")
qsock = qsocket.udp()
qsock:setoption("reuseaddr",true)
qsock:setsockname("0.0.0.0",5010)
qsock:setpeername("10.2.21.167",5351)

-- clickhouse服务（t_cshw_app_log表）
csocket = require("socket")
csock = csocket.udp()
csock:setoption("reuseaddr",true)
csock:setsockname("0.0.0.0",5003)
csock:setpeername(CLICKHOUSE_LOG_SERVER.ADDR,CLICKHOUSE_LOG_SERVER.PORT)

math.randomseed(os.time())

----------------util----------------------------------------
u_util = require "models/user/u_util"			-- 蜜蜂作业账户
c_util = require "models/class/c_util"			-- 蜜蜂作业学生作业
class_info_util = require "models/class_info/class_info_util"
teach_util = require "models/user/teach_util"
feature_util = require "models/feature/feature_util"
s_util = require "models/school/s_util"
report_util = require "models/report/report_util"
examV2_util = require "models/examination/exam_util"
exam_scanner_util = require "models/examination/scanner_util"
exam_correct_util = require "models/examination/correct_util"
scanner_util = require "models/db_hw_question/scanner_util"
personal_util = require "models/personal/personal_util"
library_util = require "models/library/library_util"
n_util = require "models/class/n_util"
xy_stat_util = require "models/library/xy_stat_util"
exam_release_util = require "models/examination/exam_release_util"
exam_stat_util = require "models/examination/exam_stat_util"
exam_ai_repush = require "models/examination/exam_ai_repush"
exam_classroom_util = require "models/examination/exam_classroom_util"
ai_receive_data_util = require "models/examination/ai_receive_data_util"


exam_question_correct_tag_util = require "models/examination/exam_question_correct_tag_util"
orm_model = require "models/orm"


------------------libs utils-------------------------------------
com_util        = require "libs/utils/com_util"
http_util       = require "libs/utils/http_util"
err_util        = require "libs/utils/err_util"
table_util        = require "libs/utils/table_util"
string_util       = require "libs/utils/string_util"
stat_util       = require "libs/utils/stat_util"
uc_api_util       = require "libs/utils/uc_api_util"
go_uc_util      = require "libs/utils/go_uc_util"
uc_util      = require "libs/utils/uc_util"
yunhui_util      = require "libs/utils/yunhui_util"
pm_util          = require "libs/utils/pm_util"
sc_util      = require "libs/utils/sc_util"
py_util      = require "libs/utils/py_util"
prometheus_push_gateway_util = require("libs.prometheus.prometheus_push_gateway_util")
push_gateway_conf = require("libs.prometheus.push_gateway_conf")

collection_util = require "libs/utils/collections"
time_util        = require "libs/utils/time_util"

orm_model = require "models/orm"
debug_util = require 'libs/utils/debug_util'
cms_util = require "libs/utils/cms_util"
------------------conf--------------------------------------
blacklist_config = require "config/blacklist_config"
other_config = require "config/other_config"
wechat_config = require "config/wechat_config"
user_config = require "config/user_config"
stat_conf       = require "config/stat_conf"
lean_analysis_config = require "config/lean_analysis_config"

----------------redis---------------------------------------
redis_conf = require "libs/redis/redis_conf"
redis_util = require "libs/redis/redis_util"
redis_util.init()

----------------- controller util ------------------------------
login_util = require "controller/user/login_util"
class_util = require "controller/class/class_util"
teacher_util = require "controller/teacher/teacher_util"
exam_util = require "controller/exam/exam_util"
message_util = require "controller/message/message_util"
survey_util = require "controller/survey/survey_util"
homework_util = require "controller/homework/homework_util"
wrong_practice_util = require "controller/homework/wrong_practice_util"
question_util = require "controller/question/question_util"
correct_util = require "controller/correct/correct_util"
course_util = require "controller/once/course_util"
config_util = require "controller/config/config_util"
public_util = require "controller/public/public_util"
vip_wrong_question_util = require "controller/homework/vip_wrong_question_util"
area_resource_util = require "controller/area_resource/db/area_resource_util"
grading_config_util = require "controller/dingtalk/homework/grading_config/grading_config_util"
dingtalk_wrong_question_util = require "controller/dingtalk/assignment/wrong/db_util"
origin_util = require "controller/examV2/paper/original_paper/paper_util"
similar_util = require "controller/examV2/similar/similar_util"
hw_similar_util = require "controller/homework/similar/similar_util"
inner_exam_helper = require "controller/examV2/exam/inner_exam_helper"
inner_similar_common_method = require "controller/examV2/similar/examinees/inner_similar_common_method"
common_msg_util = require "controller/message/wechat_msg/common_msg_util"
exam_queue_util = require "controller/queue/exam/exam_queue_util"

-------------------- service ------------------------------
user_service = require "service/user/user"
homework_service = require "service/homework/homework"
wrong_practice_service = require "service/homework/wrong_practice"
homework_report_service = require "service/homework/report"
question_service = require "service/question/question"
assignment_service = require "service/assignment/assignment"
submit_service = require "service/assignment/submit"
exam_service = require "service/exam/exam_service"
exam_scanner_service = require "service/exam/scanner_service"
exam_check_service = require "service/exam/check_service"
scanner_service = require "service/question/scanner_service"
auth_service = require "service/exam/auth_service"
examinees_service = require "service/exam/examinees_service"
stat_service = require "service/exam/stat_service"
yh_service = require "service/third_party/yh_service"
area_resource_service = require "service/area_resource/area_resource"
cockpit_service = require "service/exam/cockpit_service"
dingtalk_service = require "service/dingtalk/dingtalk"
correct_push_service = require "service/correct_push/correct_push"
exam_correct_service = require "service/exam/correct_service"
download_task_service = require "service/download_task/task"
feishu_alarm_service = require "service/feishu_alarm/feishu_alarm"
exam_similar_service = require "service/exam/exam_similar_service"
hw_similar_service = require "service/homework/similar_service"
core_quality_service = require "service/core_quality/core_quality"
core_quality_v2_service = require "service.core_quality.core_quality_v2_service"
analysis_service = require "service/analysis/analysis"
exam_block_service = require "service/exam/block_service"
exception_tag_service = require "service/exam/exception_tag_service"
scanner_submit_service = require "service/exam/scanner_submit_service"
exam_analysis = require "service/exam/analysis_service"
push_ai_service = require "service/exam/push_ai_service"
temporary_service = require "service/exam/temporary_service"
ts_paper_util = require "service/common_util/ts_paper_util"
ts_scanner_paper_util = require "service/common_util/ts_scanner_paper_util"
ts_examinees_paper_util = require "service/common_util/ts_examinees_paper_util"


-------------------- constant ------------------------------
-- 这个目录是为了存放一些业务常量
biz_practice_enum = require "constant/biz_practice_enum_config"
biz_education_config = require "constant/biz_education_config"
biz_wechat_msg_config = require "constant/biz_msg_config"
biz_exam_enum = require "constant/biz_exam_enum_config"
biz_alter_enum = require "constant/biz_alter_enum_config"
cjson.encode_empty_table_as_object(false)
